package com.wanbangee.marksystem.service.imp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wanbangee.marksystem.dao.StatisticsAverageRankingDao;
import com.wanbangee.marksystem.dao.StatisticsSubReportDao;
import com.wanbangee.marksystem.entities.StatisticsAverageRanking;
import com.wanbangee.marksystem.entities.StatisticsSubReport;
import com.wanbangee.marksystem.service.ClassScoreAnalyzeService;

@Service
public class ClassScoreAnalyzeServiceImpl implements ClassScoreAnalyzeService {

	@Autowired
	private StatisticsSubReportDao statisticsSubReportDao;
	@Autowired
	private StatisticsAverageRankingDao statisticsAverageRankingDao;
	
	@Override
	public Map<String, Object> selectExamClassInfo(Integer claId,Integer examId) {
		Map<String, Object> classExamInfo = new HashMap<>();
		//查询  班级平均分 班级名称/班主任/人数/数据添加日期
		classExamInfo = statisticsSubReportDao.selectExamClassInfo(claId, examId);
		
		//根据班级id，考试id查询此班级的年级排名
		int rank = statisticsSubReportDao.selectExamClassRank(claId, examId);
		classExamInfo.put("rank", rank);
		
		//获取前面查询到的班级此次考试成绩发布的时间
		String addTime = (String) classExamInfo.get("add_time");
		
		//根据班级ID，和班级此次考试成绩发布的时间查询上一次班级考试的年级排名
		int formerRank = statisticsSubReportDao.selectExamClassFormerRank(claId,addTime);
		
		//年级排名变化
		int rankChange = formerRank - rank;
		classExamInfo.put("rankChange", rankChange);
		System.out.println(classExamInfo);
		return classExamInfo;
	}

	@Override
	public List<StatisticsAverageRanking> selectClassSubInfo(Integer claId, Integer examId) {
		
		//根据班级Id和考试Id调用calssScoreAnalyzeDao的selectClassSubInfo方法，查询该班级本次考试的所有科目的信息
		return statisticsAverageRankingDao.selectClassSubInfo(claId, examId);
	}


	
}
